package com.tengju.bff.interfaces.data.vo;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhang
 * @Date 2020/12/25
 */
@Data
public class AchievementBonusMidInfoVO {
    List<AchievementBonusMidDetailVO> detailVOList;
    List<AchievementBonusMidInfoVO> children;

    public void add(AchievementBonusMidInfoVO childMidInfo) {
        if (CollectionUtils.isEmpty(children)) {
            children = new ArrayList<>();
        }
        children.add(childMidInfo);
    }

    public StringBuilder print(Integer depth) {
        StringBuilder sb = new StringBuilder();
        AchievementBonusMidDetailVO detailVOFirst = detailVOList.get(0);
        StringBuilder tabSb = new StringBuilder();
        for (int i = 0; i < depth; i++) {
            sb.append("\t");
            tabSb.append("\t");
        }
        sb.append("L" + depth).append(": ").append(detailVOFirst.getIdCode()).append("\r\n");
        detailVOList.forEach(v -> {
            sb.append(tabSb).append("\t").append(v.toString());
        });
        if (CollectionUtils.isEmpty(children)) {
            return sb;
        }
        for (AchievementBonusMidInfoVO child : children) {
            StringBuilder childrenPrint = child.print(depth + 1);
            sb.append(childrenPrint);
        }
        return sb;

    }


}
